package com.hopster;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import android.app.AlarmManager;
import android.app.Application;
import android.app.PendingIntent;
import android.content.Context;

public class EventService extends Application
{
	private static final EventService instance = new EventService();
	
	private static List<Event> events;
	
    // Private constructor prevents instantiation from other classes
    private EventService()
    {
    	// TODO: Initialize list from local storage.
    	events = new ArrayList<Event>();
    }
    
    /**
     * Gets the current (and only) instance of EventService.
     * @return The only EventService object.
     */
    public static EventService getInstance()
    {
    	return instance;
    }
    
    /**
     * Attempts to add the given event to the list of current events.
     * @param event Event to add.
     * @return False if an event with the same name already exists, true otherwise.
     */
    @SuppressWarnings("unchecked")
	public boolean addEvent(Event event)
    {
    	if(events.contains(event))
    	{
    		return false;
    	}
    	else
    	{
    		boolean success = events.add(event);
    		Collections.sort(events);
    		return success;
    	}
    }
    
    /**
     * Attempts to remove the event with the given name from the list of events.
     * @param event Event to remove.
     * @return True if successful, false otherwise.
     */
    public boolean removeEvent(Event event)
    {
    	return events.remove(event);
    }
   
    public List<Event> getEvents()
    {
    	return events;
    }
}
